#include "ZDynObject.h"


mapStrFun* ZDynObject::m_pClassDynCreateMap = NULL;

ZDynObjectInfo::ZDynObjectInfo( const QString& sType, ZDynCreateObjectFunPtr pFun )
{
	if(NULL == ZDynObject::m_pClassDynCreateMap)
	{
		ZDynObject::m_pClassDynCreateMap = new mapStrFun();
	}

	auto i = ZDynObject::m_pClassDynCreateMap->find(sType);
	if (i == ZDynObject::m_pClassDynCreateMap->end())
	{
		(*ZDynObject::m_pClassDynCreateMap)[sType] = pFun;
	}
	else
	{
		i->second = pFun;
	}
}

ZDynObject* ZDynObject::CreateObjFromName( const QString& sClassName )
{
	ZDynCreateObjectFunPtr funPtr = (*m_pClassDynCreateMap)[sClassName];
	if (NULL != funPtr)
	{
		return funPtr();
	}

	return NULL;
}
